package sy.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

 
import sy.dao.BaseDaoI;
import sy.model.Tmenu;
import sy.model.Tuser;
import sy.service.RepairServiceI;
import sy.util.base.MD5Util;

@Service("repairService")
public class RepairServiceImpl implements RepairServiceI {

	@Autowired
	private BaseDaoI<Tmenu> menuDao;
	@Autowired
	private BaseDaoI<Tuser> userDao;
 
 	public void repairMenu() {
		Tmenu root = new Tmenu();
	 
	
		Tmenu xtgl = new Tmenu();
		xtgl.setId("01");
		xtgl.setText("系统管理");
		xtgl.setIconcls("ext-icon-application_view_tile");
 		menuDao.saveOrUpdate(xtgl);
 
		Tmenu yhgl = new Tmenu();
		yhgl.setId("01001");
		yhgl.setText("用户管理");
		yhgl.setUrl("/admin/yhgl.jsp");
		yhgl.setTmenu(xtgl);
		yhgl.setIconcls("ext-icon-user_suit");
		menuDao.saveOrUpdate(yhgl);

		Tmenu jsgl = new Tmenu();
		jsgl.setId("01002");
		jsgl.setText("角色管理");
		jsgl.setTmenu(xtgl);
		jsgl.setIconcls("ext-icon-tux");
		menuDao.saveOrUpdate(jsgl);
		
		Tmenu cdgl = new Tmenu();
		cdgl.setId("01003");
		cdgl.setText("菜单管理");
		cdgl.setTmenu(xtgl);
		cdgl.setIconcls("ext-icon-newspaper_link");
		menuDao.saveOrUpdate(cdgl);
		
		
		Tmenu qxgl = new Tmenu();
		qxgl.setId("01004");
		qxgl.setText("权限管理");
		qxgl.setTmenu(xtgl);
		menuDao.saveOrUpdate(qxgl);
		
		
		Tmenu bug = new Tmenu();
		bug.setId("01005");
		bug.setText("BUG管理");
		bug.setTmenu(xtgl);
		menuDao.saveOrUpdate(bug);
		
 
		Tmenu xtjk = new Tmenu();
		xtjk.setId("02");
		xtjk.setText("系统监控");
 		menuDao.saveOrUpdate(xtjk);
	 
 		
 		Tmenu xmjk = new Tmenu();
 		xmjk.setId("02001");
 		xmjk.setText("项目监控");
 		xmjk.setTmenu(xtjk);
 		menuDao.saveOrUpdate(xmjk);
 		
 		Tmenu sjyjk = new Tmenu();
 		sjyjk.setId("02002");
 		sjyjk.setText("数据源监控");
 		sjyjk.setTmenu(xtjk);
 		menuDao.saveOrUpdate(sjyjk);
 		
 		Tmenu aysjk = new Tmenu();
 		aysjk.setId("02003");
 		aysjk.setText("Action映射监控");
 		aysjk.setTmenu(xtjk);
 		menuDao.saveOrUpdate(aysjk);
 		
 		Tmenu yhjk = new Tmenu();
 		yhjk.setId("02004");
 		yhjk.setText("用户登录历史监控");
 		yhjk.setTmenu(xtjk);
 		menuDao.saveOrUpdate(yhjk);
 		
 		
 		
 		
		Tmenu xttb = new Tmenu();
		xttb.setId("03");
		xttb.setText("报表管理");
		menuDao.saveOrUpdate(xttb);
		
		Tmenu zcfb = new Tmenu();
		zcfb.setId("03001");
		zcfb.setText("注册时间分布");
		zcfb.setTmenu(xttb);
 		menuDao.saveOrUpdate(zcfb);
		
		
		
		
	}
	public void repairUser() {
		Map<String,Object> map=new HashMap<String, Object>();
		map.put("name","admin");
 		Tuser t=userDao.get("from Tuser t where t.name=:name and t.id!='0'",map);
		t.setName(UUID.randomUUID().toString());
		userDao.saveOrUpdate(t);
		
		
		Tuser user=new Tuser();
		user.setId("0");
		user.setName("admin");
		user.setPwd(MD5Util.md5("12345"));
		user.setModifydatetime(new Date());
		userDao.saveOrUpdate(user);
	}
	
	public void repair(){
		repairMenu();
	//	repairUser();
	}
	
	@Override
	public void delete() {

	}

	
}
